package com.koron.css2.newProjectCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.query.PjMaterialQueryBean;
import com.koron.css2.newProjectCenter.mapper.PjMaterialMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 工程材料单删除
 */
public class PjMaterialDelete implements ServerInterface {

    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjMaterialQueryBean pjMaterialQuery = JsonUtils.objectToPojo(req.getData(), PjMaterialQueryBean.class);
            if (pjMaterialQuery.getIdList().size() == 0){
                return MessageBean.create(Constant.MESSAGE_INT_FAIL,"请勾选需要删除的数据",null);
            }
            PjMaterialMapper pjMaterialMapper = factory.getMapper(PjMaterialMapper.class);
            // 循环通过主键ID批量删除
            pjMaterialMapper.deleteByIdList(pjMaterialQuery.getIdList());
            // 3. 返回结果
            return MessageBean.create(Constant.MESSAGE_INT_SUCCESS,"工程材料列表删除成功", Void.class);
        } catch (Exception e) {
            logger.error("工程材料列表删除失败" + e);
        }
        return MessageBean.create(Constant.MESSAGE_INT_FAIL,"工程材料列表删除失败",Void.class);
    }
}
